#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import scrapy


class Zsipier(scrapy.Spider):
    name = "gongye"
    allowed_domains = "gyxkz.aqsiq.gov.cn"
    start_urls = ['http://gyxkz.aqsiq.gov.cn/eiss/zj_hzqy_query?model=00000000000000010194&nid=000261&page=1&pagecount=20']
    
    def parse(self,response):
        cominfo = cominfoitem()
        loaderCom = ItemLoader(item=cominfoitem())
        
        if response.xpath('/html/body/form/table[2]/tbody/tr[2]/td[2]'):
            com = response.xpath('/html/body/form/table[2]/tbody/tr/td[2]'/text()).extract()
            
            for com_list in com:
                cominfo['com_name'] = com_list
                loaderCom.add_value('com_name',cominfo['com_name'])
                yield loaderCom.load_item()
            page = re.findall('94&nid=000261&page=(\d+)', response.url)[0]
            curr_page = int(page)+1
            yield scrapy.Request('http://gyxkz.aqsiq.gov.cn/eiss/zj_hzqy_query?model=00000000000000010194&nid=000261&page=%d&pagecount=20' % curr_page, callback= self.parse)
                
                
            
            
    
    